<template>
	<view class="content">
    <!-- <uni-nav-bar height="65px" dark shadow left-icon="left" leftText="返回" rightText="设置" title="自定义高度" /> -->
    <view>{{ nickName }}</view>
    <view id="cja" class="asd" @click="jjj">你哈{{ item_a }}</view>
    <button open-type="chooseAvatar" @chooseavatar="chooseavatar">获取用户头像</button>
    <button open-type="getUserInfo" @getuserinfo="getuserinfo">获取用户信息</button>
    <button  @click="login">获取用户信息(api)</button>
    <image class="avatar" :src="avatarUrl"></image>

    <button open-type="getPhoneNumber" @bindgetrealtimephonenumber="getrealtimephonenumber">21212</button>
    <uni-pagination :total="50" title="标题文字" />
	</view>
</template>

<script>
import { mapState,mapMutations } from 'vuex';
	export default {
		data() {
			return {
				title: 'Hello',
        avatarUrl:"",
        userInfo:{},
        nickName:"132132"
			}
		},
    onLoad() {
			// sessionStorage.setItem("asd","ashdkjashd")
			console.log("加载开始")
		},
		onShow(){
			console.log('显示')
		},
		onHide(){
			console.log("消失");
		},
		methods: {
      login(){
        let oj=uni.getStorageSync('storage_key');
        console.log(oj);
        console.log(12)
        uni.login({
          success(res){
            console.log(res)
          }
        })
        // uni.getUserProfile({
        //   desc:"测试",
        //   success(res){
        //     console.log(res)
        //   }
        // })
      },
      getuse(){
        uni.login({
          "provider": "weixin",
          "onlyAuthorize": true, // 微信登录仅请求授权认证
          success: function(event){
            const {code} = event
            //客户端成功获取授权临时票据（code）,向业务服务器发起登录请求。
            uni.request({
                url: 'https://www.example.com/loginByWeixin', //仅为示例，并非真实接口地址。
                data: {
                    code: event.code
                },
                success: (res) => {
                  console.log(res)
                    //获得token完成登录
                uni.setStorageSync('token',res.token)
                }
            });
          },
          fail: function (err) {
                // 登录授权失败
                // err.code是错误码
            }
        })

      },
      chooseavatar(res){
        console.log(res,'131')
        this.avatarUrl=res.detail.avatarUrl
        // console.log(avatarUrl)
        uni.login({
          success(resolut){
            console.log(resolut)
          }
        })

      },
      getuserinfo(res){
        console.log(res,1212)
      },
      getrealtimephonenumber(res){
        console.log(res,'11')
      },
      ...mapMutations('state',[
        'setUserId'
      ]),
			jjj(){
        console.log(this.id_asd)
        this.setUserId("123132")
        const query = uni.createSelectorQuery().in(this);
        query.select('.asd')
        .fields(
          {
            properties:['id','class'],
            context:true,
            size: true,
            scrollOffset: true,
          },
          (data) => {
            console.log("得到节点信息" + JSON.stringify(data));
            console.log("节点的宽为" + data.width);
          }
        )
          .exec();
      }
			
		},
    computed:{
      ...mapState({
        item_a: (state) => state.state.user.id
      })
    }
	}
</script>

<style>
	.content {
    width: 100%;
		
	}

</style>
